package org.
robustcoupe.task.example;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.robustcoupe.task.TaskResultType;
import org.robustcoupe.task.example.resources.NullPointerExceptionTask;
import static org.robustcoupe.task.NestedFunctionStyle.*;

public class TryCatchDecoratorExample {
  private static final Log LOG = LogFactory.getLog(TryCatchDecoratorExample.class);
  
  public static void main(String[] args) {
    TaskResultType result = 
      new NullPointerExceptionTask()
        .wrappedByTryCatch()
          .loggable(true)
          .resultWhenFailed(TaskResultType.FAILURE)
      .execute();
    LOG.info(result);

    result = 
    tryCatch(
        task(new NullPointerExceptionTask()), 
        loggable(true), 
        resultWhenFailed(TaskResultType.FAILOVER)
    ).execute();
    LOG.info(result);
  }
}
